<template>
  <div>
    <!-- 头部 -->
    <div class="header">
      <router-link to="/home"
        ><img src="./img/xz.png" alt="" class="fh"
      /></router-link>
      <p class="shopCart">购物车</p>
      <img src="./img/download (1).png" alt="" class="fd" />
    </div>
    <!-- 中间 -->
    <div class="main">
      <div v-show="show">
        <div class="mainTop">
          <span>登录后享受更多优惠</span>
          <router-link to="/login"><em class="denglu">去登录</em></router-link>
          <img src="./img/xz.png" alt="" class="qw"/>
        </div>
        <div class="noitems">
          <img src="./img/cartnull.daaf7926f8.png" alt="" class="gwc" />
          <span>购物车还是空的</span>
          <em>去逛逛</em>
        </div>
        <div class="recommend">
          <img src="./img/3f00943bf04702405b8e8bc9f404a9f6.png" alt="" />
        </div>
      </div>
      <div v-show="!show">
        <div class="radio">
          <div
            v-for="(info, index) in phone"
            :key="index"
            style="display: flex"
          >
            <van-checkbox v-model="checked" checked-color="#ee0a24">
            </van-checkbox>
            <van-card
              :desc="info.price"
              :title="info.name"
              :thumb="info.image_url"
            >
              <template #tags>
                <!-- 步进器 -->
                <van-stepper
                  max="5"
                  v-model="info.buyNum"
                  @change="handle(info.id)"
                  name="name"
                  integer
                  input-width="40px"
                  button-size="32px"
                />
                <div class="delete" @click="Delete(info.id)">
                  <svg
                    t="1641386990705"
                    class="icon"
                    viewBox="0 0 1024 1024"
                    version="1.1"
                    xmlns="http://www.w3.org/2000/svg"
                    p-id="2153"
                    width="16"
                    height="16"
                  >
                    <path
                      d="M607.897867 768.043004c-17.717453 0-31.994625-14.277171-31.994625-31.994625L575.903242 383.935495c0-17.717453 14.277171-31.994625 31.994625-31.994625s31.994625 14.277171 31.994625 31.994625l0 351.94087C639.892491 753.593818 625.61532 768.043004 607.897867 768.043004z"
                      p-id="2154"
                    ></path>
                    <path
                      d="M415.930119 768.043004c-17.717453 0-31.994625-14.277171-31.994625-31.994625L383.935495 383.935495c0-17.717453 14.277171-31.994625 31.994625-31.994625 17.717453 0 31.994625 14.277171 31.994625 31.994625l0 351.94087C447.924744 753.593818 433.647573 768.043004 415.930119 768.043004z"
                      p-id="2155"
                    ></path>
                    <path
                      d="M928.016126 223.962372l-159.973123 0L768.043004 159.973123c0-52.980346-42.659499-95.983874-95.295817-95.983874L351.94087 63.989249c-52.980346 0-95.983874 43.003528-95.983874 95.983874l0 63.989249-159.973123 0c-17.717453 0-31.994625 14.277171-31.994625 31.994625s14.277171 31.994625 31.994625 31.994625l832.032253 0c17.717453 0 31.994625-14.277171 31.994625-31.994625S945.73358 223.962372 928.016126 223.962372zM319.946246 159.973123c0-17.545439 14.449185-31.994625 31.994625-31.994625l320.806316 0c17.545439 0 31.306568 14.105157 31.306568 31.994625l0 63.989249L319.946246 223.962372 319.946246 159.973123 319.946246 159.973123z"
                      p-id="2156"
                    ></path>
                    <path
                      d="M736.048379 960.010751 288.123635 960.010751c-52.980346 0-95.983874-43.003528-95.983874-95.983874L192.139761 383.591466c0-17.717453 14.277171-31.994625 31.994625-31.994625s31.994625 14.277171 31.994625 31.994625l0 480.435411c0 17.717453 14.449185 31.994625 31.994625 31.994625l448.096758 0c17.717453 0 31.994625-14.277171 31.994625-31.994625L768.215018 384.795565c0-17.717453 14.277171-31.994625 31.994625-31.994625s31.994625 14.277171 31.994625 31.994625l0 479.231312C832.032253 916.835209 789.028725 960.010751 736.048379 960.010751z"
                      p-id="2157"
                    ></path>
                  </svg>
                </div>
              </template>
            </van-card>
          </div>
        </div>

        <van-field
          v-model="fieldValue"
          is-link
          readonly
          label="保险"
          placeholder=" MiCare保障服务 599元"
          @click="show = true"
        />
        <van-popup v-model="show" round position="bottom">
          <van-cascader
            v-model="cascaderValue"
            title="购买服务"
            :options="options"
            @close="show = false"
            @finish="onFinish"
          />
        </van-popup>
        <div class="point">
          <p>温馨提示：产品是否购买成功，以最终下单为准，请尽快结算</p>
        </div>
        <div class="recommend">
          <img src="./img/3f00943bf04702405b8e8bc9f404a9f6.png" alt="" />
        </div>
      </div>

      <!-- 推荐商品 -->
      <router-link to="/home">
        <div class="recommend-list">
          <div
            class="goods-item"
            v-for="(cart, index) in recom_list"
            :key="index"
          >
            <img :src="cart.image_url" alt="" />
            <div class="goods-info">
              <p>{{ cart.name }}</p>
              <p class="goods-price">
                <span>￥{{ cart.price }}</span>
              </p>
            </div>
          </div>
        </div>
      </router-link>
    </div>
    <!-- 底部 -->
    <div class="footer" v-show="!show">
      <div class="price" v-for="(info, index) in phone" :key="index">
        <span>共1件,金额:</span>
        <strong>2400</strong><i>元</i>
      </div>

      <button style="background: #f4f4f4">
        <router-link to="/home">继续购物</router-link>
      </button>
      <button :disabled='!checked' @click="click" class="js" style="color: #fff">去结算</button>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import { mapState } from "vuex";
export default {
  name: "Cart",
  data() {
    return {
      show:true,
      price: "",
      phone: [],
      checked: true,
      activeIcon: "https://img01.yzcdn.cn/vant/user-active.png",
      inactiveIcon: "https://img01.yzcdn.cn/vant/user-inactive.png",
      buyNum: 1,
      show: false,
      fieldValue: "",
      cascaderValue: "",
      // 选项列表，children 代表子选项，支持多级嵌套
      options: [
        {
          text: "至尊服务",
          value: "330000",

          children: [{ text: "MiCare保障服务 599元", value: "330100" }],
        },
      ],
    };
  },
  computed: {
    ...mapState({
      recom_list: (state) => state.cart.cartDetail.recom_list,
    }),
  },
  mounted() {
    this.$store.dispatch("getShopCartList");
    // console.log(this.phone);
    
    this.phone.push(this.$route.params);
    //隐藏
    if(this.$route.params.id){
      this.show = false
    }else{
      this.show = true
    }
  },
  methods: {
    //删除
    Delete(id) {
      if (id) {
        this.phone = "";
      }
    },
    click() {
      Toast({
        message: "底部展示",
        position: "bottom",
      });
    },
    // 全部选项选择完毕后，会触发 finish 事件
    onFinish({ selectedOptions }) {
      this.show = false;
      this.fieldValue = selectedOptions.map((option) => option.text).join("/");
    },
   
    
    click() {
      Toast.success("成功支付");
    },
  },
};
</script>

<style lang="less" scoped>
.header {
  position: fixed;
  top: 0;
  left: 0;
  background: #f2f2f2;
  width: 100%;
  line-height: 0.2rem;
  padding: 0.1rem 0.1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 999;
  .shopCart {
    width: 2.71rem;
    text-align: center;
    font-size: 0.15rem;
    color: #666;
    line-height: 0.3rem;
  }
  .fh {
    width: 0.26rem;
    height: 0.26rem;
  }
  .fd {
    width: 0.3rem;
    height: 0.3rem;
    margin-right: 0.2rem;
  }
}
.main {
  margin-top: 0.5rem;
  .mainTop {
    position: relative;
    height: 0.55rem;
    line-height: 0.55rem;
    font-size: 0.17rem;
    padding: 0 0.29rem 0 0.16rem;
    .denglu {
      font-size: 0.12rem;
      color: #666;
      font-weight: 400;
      font-style: normal;
      float: right;
    }
    .qw {
      position: absolute;
      right: 0.1rem;
      top: 0.18rem;
      transform: rotate(180deg);
      width: 0.2rem;
      height: 0.2rem;
    }
  }
  .noitems {
    height: 0.39rem;
    padding: 0.11rem;
    line-height: 0.31rem;
    text-align: center;
    font-size: 0.125rem;
    background-color: #ebebeb;
    .gwc {
      width: 0.41rem;
      height: 0.41rem;
      vertical-align: middle;
    }
    span {
      display: inline-block;
      height: 0.41rem;
      color: #999;
      padding-left: 0.1rem;
    }
    em {
      height: 0.265rem;
      line-height: 0.265rem;
      display: inline-block;
      border: 0.01rem solid #ccc;
      font-style: normal;
      margin: 0 0.1rem;
      padding: 0 0.1rem;
      font-size: 0.12rem;
    }
  }
  .recommend {
    height: 0.63rem;

    img {
      display: block;
      width: 100%;
      height: 100%;
    }
  }
  .radio {
    display: flex;
    flex-direction: column;
  }
  .recommend-list {
    margin-top: 0.03rem;
    display: flex;
    justify-content: space-between;
   height: 10.45rem;
    overflow: scroll;
    box-sizing: border-box;
    flex-wrap: wrap;
    .goods-item {
      width: 1.86rem;

      img {
        display: block;
        width: 1.85rem;
        min-height: 1.85rem;
      }
    }
    .goods-info {
      height: calc(100% - 1.86rem);
      padding: 0.09rem 0.13rem 0.11rem;
      font-size: 0.14rem;
      .goods-price {
        span {
          font-size: 0.166rem;
          color: #ff6700;
        }
        i {
          font-size: 0.12rem;
          color: #666;
          font-style: normal;
        }
      }
    }
  }
  .point {
    height: 0.2rem;
    font-size: 0.13rem;
    color: #999;
    border-top: 0.01rem solid #f6f6f6;
    padding: 0.2rem 0.3rem;
    text-align: left;
    p {
      display: block;
    }
  }
  ::v-deep .van-card__thumb img {
    height: 100%;
    width: 100%;
    object-fit: cover;
    margin-top: 0.15rem;
  }
  ::v-deep .van-checkbox {
    margin-left: 0.05rem;
  }
  ::v-deep .van-card__desc {
    font-size: 0.12rem;
    color: #999;
  }
  ::v-deep .van-card__title {
    font-size: 0.16rem;
    margin-top: 0.2216rem;
  }
  ::v-deep .van-card {
    padding: 0.18rem 0.16rem;
  }
  ::v-deep .van-stepper {
    display: inline-block;
  }

  ::v-deep svg {
    padding: 0;
    font-size: 0.2rem;
    margin-left: 1.8rem;
  }
}
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  z-index: 99;
  box-shadow: 0 0.03rem 0.14rem 0.02rem rgba(1, 0, 0, 0.12);
  height: 0.56rem;
  line-height: 0.56rem;
  font-size: 0.28rem;
  display: flex;
  .price {
    width: 1.24rem;
    font-size: 0.12rem;
    color: #999;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    span {
      width: 0.795rem;
      height: 0.16rem;
      margin-top: -0.07rem;
    }
    strong {
      font-weight: 700;
      color: #ff6700;
      font-size: 0.18rem;
      margin-top: 0.05rem;
    }
    i {
      margin-top: 0.05rem;
    }
  }
  button {
    width: 1.35rem;
    text-align: center;
    font-size: 0.145rem;
    border: none;
  }
  .js {
    background: #ff6700;
  }
}
</style>